<template>
	<view>
		<fa-navbar title="入会申请"></fa-navbar>
		<view class="prompt">
			* 请完善以下信息
		</view>

		<view class="list">
			<view class="item" v-for="(v,i) in list" :key="i" :class="{flex: i !== 9}">
				<view class="left">
					{{v.title}}
				</view>
				<view class="right" @click="openSelect(i)">
					<!-- status == 1 -->
					<input v-if="v.status == 1" type="text" :placeholder="v.placeholder" v-model="v.value"
						placeholder-style="color:#b8b8b8;" />
					<!-- status == 3 -->
					<view class="openSelect" style="color: #b8b8b8;" v-if="v.status == 3 && v.value == ''">
						请选择<u-icon name="arrow-down"></u-icon>
					</view>
					<view class="openSelect" v-if="v.status == 3 && v.value != ''">
						{{v.value}}
					</view>
					<!-- status == 5 -->
					<view class="textarea" v-if="v.status == 5" style="margin-top: -45rpx;">
						<textarea v-model="v.value" :placeholder="v.placeholder" placeholder-style="color:#b8b8b8;" />
					</view>

				</view>
			</view>
		</view>
		<view class="lastPage" @click="last">
			返回上一页
		</view>
		<view class="submit" @click="submit">
			提交申请
		</view>
		<view class="" style="height: 30rpx;">

		</view>

		<!-- 企业类型 -->
		<u-select v-model="enterpriseTypeShow" :list="enterpriseType" @confirm='enterpriseTypeConfirm'></u-select>
		<!-- 企业行业分类 -->
		<u-select v-model="industryShow" :list="industry" @confirm='industryConfirm'></u-select>
		<!-- 省市区 -->
		<u-picker mode="region" v-model="reginShow" @confirm='regionConfirm'></u-picker>

	</view>
</template>

<script>
	export default {

		data() {
			return {
				reginShow: false,
				industryShow: false,
				industry: [],
				enterpriseTypeShow: false,
				enterpriseType: [],
				list: [{
						title: '企业类型',
						value: '',
						status: 3,
						check: '请选择企业类型'
					},
					{
						title: '企业行业分类',
						value: '',
						status: 3,
						check: '请选择企业行业分类'
					},
					{
						title: '统一社会信用号',
						value: '',
						status: 1,
						placeholder: '请填写统一社会信用号码',
						check: '请填写统一社会信用号码'
					},
					{
						title: '企业注册地',
						value: '',
						status: 3,
						check: '请选择企业注册地'
					},
					{
						title: '企业所在地址',
						value: '',
						status: 1,
						placeholder: '请填写企业所在地址',
						check: '请填写企业所在地址'
					},
					{
						title: '销售总额(万元)',
						value: '',
						status: 1,
						placeholder: '请填写销售总额',
						check: '请填写销售总额'
					},
					{
						title: '员工总数(人)',
						value: '',
						status: 1,
						placeholder: '请填写员工总人数',
						check: '请填写员工总人数'
					},
					{
						title: '企业联络员',
						value: '',
						status: 1,
						placeholder: '请填写联络员姓名',
						check: '请填写联络员姓名'
					},
					{
						title: '企业联络员电话',
						value: '',
						status: 1,
						placeholder: '请填写联络员电话',
						check: '请填写联络员电话'
					},
					{
						title: '企业简介',
						value: '',
						status: 5,
						placeholder: '请填写企业简介',
						check: '请填写企业简介'
					},
				]
			}
		},
		created() {
			this.getSelectList()
			const form2 = uni.getStorageSync('secondForm')
			if (form2) {
				this.list = form2
			}
		},
		methods: {
			regionConfirm(e) {
				this.list[3].value = e.province.label + e.city.label + e.area.label
			},
			openSelect(index) {
				if (index == 0) {
					this.enterpriseTypeShow = true
				} else if (index == 1) {
					this.industryShow = true

				} else if (index == 3) {
					this.reginShow = true
				}
			},
			industryConfirm(e) {
				this.list[1].value = e[0].label
			},
			enterpriseTypeConfirm(e) {
				this.list[0].value = e[0].label
			},
			async getSelectList() {
				let res = await this.$api.getSelectList()
				if (!res.code) {
					this.$u.toast(res.msg)
					return
				}
				console.log(res, 'res');

				const modifiedData = res.data.enterprise_event.map(item => {
					return {
						value: item.value,
						label: item.name
					};
				});
				const modifiedData1 = res.data.industry_cate.map(item => {
					return {
						value: item.value,
						label: item.name
					};
				});
				this.industry = modifiedData1
				this.enterpriseType = modifiedData
			},
			submit() {
				// 判断列表中每个元素的value属性是否有值
				const hasValue = this.list.every(item => item.value);

				if (!hasValue) {
					// 如果有任何一个元素的value属性没有值，提取其对应的placeholder属性
					const missingPlaceholders = this.list.filter(item => !item.value).map(item => item.check);
					// 输出没有值的placeholder

					uni.showModal({
						title: '友情提示',
						content: missingPlaceholders[0],
						showCancel: false
					})
					// 这里可以将错误信息展示给用户或者采取其他逻辑处理
					return;
				}
				uni.setStorageSync('secondForm', this.list)
				this.$u.route('/pages/applicationForm/confirmForm');
			},
			last() {

				this.$u.route('/pages/applicationForm/applicationForm');
			},
			handleHometownSelection(selectedData) {
				console.log('Selected Hometown:', selectedData);
			},

		}
	};
</script>

<style scoped lang="scss">
	/* 可以添加页面样式 */
	.prompt {
		width: 749rpx;
		height: 57rpx;
		background-color: #f5dfe1;
		color: #d9001b;
		line-height: 57rpx;
		padding-left: 38rpx;
		font-size: 26rpx;
	}

	.list {
		padding: 0rpx 35rpx;
		font-size: 31rpx;

		.flex {
			display: flex;
		}

		.item {


			border-bottom: 3rpx solid #ececec;

			.left {
				padding: 35rpx 0rpx;
				width: 250rpx;
			}

			.right {
				padding: 35rpx 0rpx;
				color: #000;
				flex: 1;

				input {
					width: 100%;
				}

				.openSelect {
					/deep/ .u-icon__icon {
						margin-left: 20rpx;
					}
				}

				.code {
					display: flex;

					input {
						width: 300rpx;
					}

					.btn {
						width: 130rpx;
						height: 50rpx;
						border-radius: 7rpx;
						border: solid 1rpx #d9001b;
						text-align: center;
						line-height: 50rpx;
						color: #d9001b;
						font-size: 24rpx;
						margin-top: -7rpx;
					}
				}

				.textarea {
					width: 683rpx !important;
					height: 212rpx !important;
					background-color: #f8f7f7;
					border-radius: 10rpx;
					padding: 25rpx 20rpx;

					textarea {
						width: 630rpx !important;
						height: 170rpx !important;
					}
				}
			}

		}

		.upload {
			padding: 35rpx 0rpx;

			.title {
				font-size: 31rpx;
			}

			.type {
				font-size: 20rpx;
				color: #585858;
				margin-top: 10rpx;
			}

			.image {
				width: 156rpx;
				height: 156rpx;
				border-radius: 4rpx;
				margin-top: 20rpx;

				image {
					width: 100%;
					height: 100%;
					border-radius: 4rpx;
				}
			}

			/deep/ .u-delete-icon {
				width: 30rpx;
				height: 30rpx;
				top: 0rpx !important;
				right: 0rpx !important;
			}
		}
	}

	.lastPage {
		width: 650rpx;
		height: 67rpx;
		background-color: #fff;
		border-radius: 10rpx;
		color: #d9001b;
		text-align: center;
		border: solid 1rpx #d9001b;

		line-height: 67rpx;
		font-size: 26rpx;
		margin: 0rpx auto;
	}

	.submit {
		width: 650rpx;
		height: 67rpx;
		background-color: #d9001b;
		border-radius: 10rpx;
		color: #fff;
		text-align: center;
		line-height: 67rpx;
		font-size: 26rpx;
		margin: 30rpx auto;
	}
</style>